package com.example.smartlearning.controller;

import com.example.smartlearning.service.impl.AIServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("/Smart/AI/")
public class AIController {


    @Resource
    AIServiceImpl aiService;

    /**
     * AI 对话
     *
     * @param text 输入文字
     * @return 返回值
     */
    @PostMapping("AIDialog")
    public String AIDialog(@RequestParam("text") String text) {
        return aiService.AIDialog(text);
    }

    /**
     * 拍照识别
     *
     * @param file 上传图片
     * @return 返回识别结果
     */
    @PostMapping("AiITR")
    public String AiITR(@RequestParam("file") MultipartFile file) {
        return aiService.AiITR(file);
    }

    /**
     * 机器翻译接口
     *
     * @param SourceLanguage zh表示中文
     * @param TargetLanguage en表示英文
     * @param SourceText     需要翻译的字符
     * @return 返回翻译结果
     */
    @PostMapping("AITranslate")
    public String AITranslate(
            @RequestParam("SourceLanguage") String SourceLanguage,
            @RequestParam("TargetLanguage") String TargetLanguage,
            @RequestParam("SourceText") String SourceText
    ) {
        return aiService.AITranslate(SourceLanguage, TargetLanguage, SourceText);
    }

    /***
     * 文字识别接口
     * @param file 文件
     * @return 返回
     */
    @PostMapping("OCR")
    public String OCR(@RequestParam("file") MultipartFile file){
        String url = aiService.upFile(file);
        return aiService.Ocr(url);
    }

    @PostMapping("Face")
    public String Face(@RequestParam("file1") MultipartFile file1,@RequestParam("file2") String file2){
        String url1 = aiService.upFile(file1);
        return aiService.face(url1,file2);
    }
    @PostMapping("Similar")
    public String Similar(@RequestParam("text1") String text1,@RequestParam("text2") String text2){
        return aiService.similar(text1, text2);
    }
}